<template>
  <div>
    <el-table :data="articles">
      <el-table-column prop="title" label="文章标题" width="120"></el-table-column>
      <el-table-column prop="body" label="内容" width="220"></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row._id)" type="success" size="small">编辑</el-button>
          <el-button @click="remove(scope.row._id)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      articles: []
    };
  },
  methods: {
    getArticleList() {
      this.$http.get("articles").then(res => {
        this.articles = res.data;
      });
    },
    edit(id) {
      console.log(id)
      this.$router.push(`/articles/${id}/edit`)
    },
    remove(id) {
      this.$http.delete(`articles/${id}`).then(() => {
        this.$message({
          message: '删除成功！',
          type: 'success'
        });
        this.getArticleList();
      })
    }
  },
  created() {
    this.getArticleList();
  }
};
</script>


  